import {createApi} from 'kuan-bear-vue'
import router from '@/router'
import {Notification} from 'element-ui'
import authority from '@/utils/authority'

export default createApi({
  options: {
    headers: {}, // 默认headers
    handleError(status) { // 自定义错误处理
      if (status === 401) router.push({name: 'login'})
    },
  },
  Alert(message) {
    Notification({
      type: 'warning',
      title: '警告',
      message
    })
  },
  getHeaders() {
    return {
      token: authority.get()
    }
  }
})
